<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="name">
        <el-input
          v-model="list.filter.name"
          placeholder="请输入名称搜索"
          clearable
        />
      </el-form-item>
      <el-form-item prop="status">
        <Status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <span>
        <auth-button @click="c" name="新增" />
      </span>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="名称" prop="name" />
      <el-table-column label="封面图片">
        <template slot-scope="scope">
          <PicViewer :value="scope.row.cover" tableCell />
        </template>
      </el-table-column>
      <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <auth-button @click="u({ id: row.id })" name="编辑" />
          <auth-button @click="d({ id: row.id })" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="文化名称" prop="name" verify>
          <el-input
            v-model="form.data.name"
            placeholder="请输入文化名称"
            maxlength="30"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="文化封面图" prop="cover" verify>
          <Imgpond v-model="form.data.cover" aspectRatio="355/158" :count="1" />
        </el-form-item>
        <el-form-item label="文化图集" prop="img" verify>
          <Imgpond v-model="form.data.img" :count="9" aspectRatio="375/375" />
        </el-form-item>
        <el-form-item label="地区文化介绍" prop="introduction" verify>
          <MiniMCE v-model="form.data.introduction" :disabled="form.status === 'r'"/>
        </el-form-item>
        <el-form-item
          label="关联景区"
          prop="scenicSpotIds"
          verify
        >
          <ScenicSpot v-if="form.show" v-model="form.data.scenicSpotIds" />
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'
import ScenicSpot from '@/components/ScenicSpot'
export default {
  mixins: [pageMixin],
  components: {
    ScenicSpot
  },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'one-travel-api/culture-content'
    })
}
</script>
